package com.zjuee.web.auth.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.service.auth.service.RoleMenuService;
import com.zjuee.service.auth.vo.RoleMenuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 角色菜单权限 web 接口
 *
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping(path = Common.Service.ZJUEE_AUTH_ROLE_MENU_URL_PREFIX, name = Common.Service.ZJUEE_AUTH_SERVICE_NAME)
public class RoleMenuController {

    @Resource
    private RoleMenuService roleMenuService;

//    @Override
//    public R<Boolean> delete(Long id) {
////        try {
////            return roleMenuService.delete(id) ? R.ok() : R.fail();
////        } catch (Exception e) {
////            return R.fail(e.getMessage());
////        }
//        return R.ok();
//    }
//
//    @Override
//    public R add(RoleMenu roleMenu) {
//        try {
//            Long add = roleMenuService.add(roleMenu);
//            if (null != add) {
//                return R.ok(add);
//            }
//        } catch (Exception e) {
//            return R.fail(e.getMessage());
//        }
//        return R.fail();
//    }

    //更新 角色-资源 关联关系
    @PutMapping("/update")
    public R<Boolean> update(@RequestBody RoleMenuVo roleMenuVo) {
        try {
            return roleMenuService.update(roleMenuVo) ? R.ok() : R.fail();
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

}
